// pages/bookEnter/bookList/listpage/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    bookList: {}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.request({
      url: `https://api.zhuishushenqi.com/book-list/${options.id}`,
      success: res => {
        res.data.bookList.books.forEach(val => {
          let cover =  val.book.cover;
          let num = cover.indexOf("http");
          cover = cover.slice(num);
          cover = decodeURIComponent(cover)
          val.book.cover = cover
        })
        res.data.bookList.books.forEach(val => {
          val.book.retentionRatio = parseInt(val.book.retentionRatio);
          val.book.wordCount = parseInt(val.book.wordCount / 10000);
        })
        let num = res.data.bookList.created.indexOf("T");
        res.data.bookList.created = res.data.bookList.created.slice(0,num);
        let nums = res.data.bookList.updated.indexOf("T");
        res.data.bookList.updated = res.data.bookList.updated.slice(0,num);
        this.setData({
          bookList: res.data.bookList 
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  toBookIntro(e){
    wx.navigateTo({
      url: `/pages/bookIntro/intro-start/index?id=${e.currentTarget.id}`,
    })
  }
})